<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>

    <meta charset="utf-8">
    <title>[[${book.title}]] 下载页面</title>
    <link rel="stylesheet" th:href="@{/css/beeui.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">

    <script th:src="@{/js/jquery-3.4.0.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>



    <style>
        html {
            background-color: rgb(248,250,252);
        }
    </style>

</head>

<body class="beeui-down-page">

    <div style="margin: 2em auto; text-align: center">
        <h2 style="color: #f67280; font-family: monospace">
            <a th:href="@{/index.html}">
                <i class="layui-icon layui-icon-return" style="float:left; font-size: 24px; color: #f67280"></i>
            </a>
            <span>[[${book.title}]]</span>
        </h2>
    </div>
    <hr style="border: 0.5px solid #f8fafc"/>
    <div class="beeui-down">
        <h4 style="font-weight: bold">下载文件资源信息</h4>
        <p>文件名称：[[${#strings.substringAfter(book.src, '/src/')}]]</p>
        <p>文件大小：[[${#numbers.formatInteger((book.size / 1024 / 1024), 1, 'POINT')}]] MB</p>
        <p>上传时间：<time>[[${#strings.substring(book.uploadTime, 0, 10)}]]</time></p>
        <p>作者信息：[[${book.author == null ? '佚名' : book.author}]]</p>
    </div>

    <div class="beeui-down">
        <p>
            下载列表：
<!--            <a th:href="@{'/download/' + ${book.id}(fileName=${#strings.substringAfter(book.src, '/src/')})}" style="color: red">开始下载</a>-->
            <a style="color: #f38181" onclick="getCount()">开始下载</a>
            <span style="margin: 0 4px">|</span>
            <a style="color: #f67280" onclick="toPreview()">在线预览</a>
        </p>
    </div>

    <div class="beeui-down">
        <p>声明：
            本站大部分下载资源收集于网络，只做学习和交流使用，版权归原作者所有。
            若为付费主题，请在下载后24小时之内自觉删除。若作商业用途，请购买正版。
            由于未及时购买和付费发生的侵权行为，与本站无关。本站发布的内容若侵犯到您的权益，请联系站长删除，我们将及时处理！</p>
    </div>

    <div style="color: #ff9999; margin: 2em auto; text-align: center">
        ©2021 <a href="http://www.newson.ltd" style="color: #ea5455" target="_blank">newson.ltd</a> 版权所有
    </div>

    <script th:inline="javascript">

        // 获取下载次数
        function getCount() {
            layui.use('layer', function () {
                let layer = layui.layer;
                let url = [[@{/downloadHistory/today/get}]];
                $.get(url, function (data) {
                    if (data < 3) {
                        layer.confirm('您还有：<span style="color: red">' + (3 - data) +'次</span>下载机会，确认下载吗?',
                            {icon: 3, title:'提示'}, function(index){
                                let downUrl = [[@{'/download/'+ ${book.themeId} + '/' + ${book.id}(fileName=${#strings.substringAfter(book.src, '/src/')})}]];
                                window.open(downUrl);
                                layer.close(index);
                            });
                    } else {
                        layer.msg('当日下载次数已用完！', {icon: 0, anim:6, time:1280});
                    }

                });
            });

        }


        // 获取在线预览
        function toPreview() {
            layui.use('layer', function () {
                let layer = layui.layer;
                let url = [[@{/downloadHistory/today/get}]];
                $.get(url, function (data) {
                    if (data < 3) {
                        layer.confirm('您还有：<span style="color: red">' + (3 - data) +'次</span>预览机会，确认预览吗?',
                            {icon: 3, title:'提示'}, function(index){
                                let downUrl = [[@{'/preview/'+ ${book.themeId} + '/' + ${book.id}(fileName=${#strings.substringAfter(book.src, '/src/')})}]];
                                window.open(downUrl);
                                layer.close(index);
                            });
                    } else {
                        layer.msg('当日预览次数已用完！', {icon: 0, anim:6, time:1280});
                    }

                });
            });

        }
    </script>

</body>
</html>